package com.lzxm.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



import com.alibaba.druid.util.StringUtils;
import com.lzxm.constant.ServerResponse;
import com.lzxm.po.Suggestion;
import com.lzxm.po.User;
import com.lzxm.service.SuggestionService;

@Controller
public class SuggestionController {
	
	@Autowired
	private SuggestionService suggestionService;
	
	
	@RequestMapping("/suggestion.do")
	@ResponseBody
	public ServerResponse insertSuggestion(HttpServletRequest request){
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		ServerResponse response;
		if(user == null){
			response = ServerResponse.createByErrorMsg("请先登陆！");
			return response;
		}
		
		String suggestion_name = request.getParameter("suggestion_name");
		
		String contactway = request.getParameter("contactway");
		String suggestion_content = request.getParameter("suggestion_content");
		int user_id=user.getUser_id();
		
		if(StringUtils.isEmpty(suggestion_name) || StringUtils.isEmpty(suggestion_content)){
			response = ServerResponse.createByErrorMsg("字段不能为空");
			return response;
		}
		
		Suggestion suggestion=new Suggestion();
		suggestion.setUser_id(user_id);
		suggestion.setSuggestion_name(suggestion_name);
		suggestion.setSuggestion_content(suggestion_content);
		suggestion.setContactway(contactway);
		suggestionService.insertSuggestion(suggestion);
		
		response = ServerResponse.createBySuccessMsg( "操作成功！");
		return response;
	}

}
